package com.project.controller;

import com.project.bean.ShopBean;
import com.project.bean.UserBean;
import com.project.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("shop")
public class ShopController {
    @Autowired
    private IShopService service;

    @RequestMapping("showShopList")
    public List<ShopBean> showShopList(HttpServletRequest req){
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        return service.findByUser(user.getId());
    }

    @RequestMapping("buy")
    public String buy(Integer productId,HttpServletRequest req){
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        service.add(user.getId(),productId);
        return "ok";
    }

    @RequestMapping("del")
    public String del(Integer shopId){
        service.del(shopId);
        return "ok";
    }

    @RequestMapping("updateNum")
    public String updateNum(Integer shopId,Integer num){
        service.updateNum(shopId,num);
        return "ok";
    }
}
